<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="cn.sumpu.app.coolsk.domain.AdminUser,cn.sumpu.app.coolsk.web.util.AdminUtil" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<%
AdminUser user = AdminUtil.getUser();
String id = null;
if (null != user) {
	id = user.getId();
	request.setAttribute("userId",id);
}
%>
<script type="text/javascript" src="/thirdparty/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	var grid_ae = null;
	var dialog_ae = null;
	$(function(){
		grid_ae = $("#order_grid").ligerGrid({
				checkbox: true,
				selectRowButtonOnly :true,
				title : '订单列表',
				onCheckAllRow:function(ischeck,data){
					grid_ae.loadData();
					alert("不可以全选，谢谢。");
				},
				onCheckRow:function(ischeck,data){
					//alert(data.manualCopyId,data.aircraftNo,dom,index);
					var orderId=data.id;
				      if(ischeck){
					    	  //alert(data.id);
					    	  $.post("/misc/order/lockorder.htm",{orderId:orderId},
										function(data){
					    		 		   //alert("您已经锁定此订单，其他人将不可操作！");
											grid_ae.loadData();
										}
									); 
				     }else{
				    	// alert(data.id);
				    	if(data.lock!="${userId}"){
					    	<sec:authorize ifAnyGranted="ROLE_ADMIN">
						    	$.post("/misc/order/unlockorder.htm",{orderId:orderId},
										function(data){
					    					//alert("您已经取消锁定！");
											grid_ae.loadData();
										}
									);
					    	 </sec:authorize>
					    	 grid_ae.loadData();
				    	}
				    	 else{
						    		if(data.lock=="${userId}"){
								    	 $.post("/misc/order/unlockorder.htm",{orderId:orderId},
													function(data){
								    					//alert("您已经取消锁定！");
														grid_ae.loadData();
													}
												); 
						    		}else{
								    	 alert("抱歉，用户"+data.lockName+"才可以解锁");
								    	 grid_ae.loadData();
						    		}
				    		 }
				    	 }
				    }, 
                columns: [
				{ display: '锁定订单人', name: 'lockName',isSort : false, width: 80 },
                { display: '订单号', name: 'id', isSort : false, width: 120,
                render: function (record, rowindex, value, column){
    						var html = '<a onclick="detail(\''+ record.id + '\')" href="javascript:;">'+ record.id + '</a>'; 
    						return html; 
    					}
                },
                { display: '产品名称', name: 'pname',isSort : false, width: 200,
                	 render: function (record, rowindex, value, column){
 						var html = '<a onclick="typeDetail(\''+ record.pid + '\',\''+ record.type + '\')" href="javascript:;">'+ record.pname + '</a>'; 
 						return html; 
 					}
                
                
                },
                { display: '产品类型', name: 'type',isSort : false, width: 100,
                	render: function (record, rowindex, value, column){
                		var html = '';
                		if(value == '01'){
                			html = '门票';
                		}else if(value == '02'){
                			html = '酒店房间';
                		}else if(value == '03'){
                			html = '产品';
                		}
						 
						return html; 
 					}
                
                
                },
                { display: '下单时间', name: 'gmtCreated',isSort : false, width: 200,
                	render: function (record, rowindex, value, column){
                		 return (new Date(value.time)).format("yyyy年MM月dd日 hh:mm:ss");
					}
                
                },
                { display: '支付类型', name: 'payFrom',isSort : false, width: 100,
                	render: function (record, rowindex, value, column){
                		var html = '';
                		if(value == '01'){
                			html = '在线支付';
                		}else if(value == '02'){
                			html = '到付';
                		}
						 
						return html; 
					}
                },
                { display: '订单状态', name: 'status',isSort : false, width: 100 ,
                	render: function (record, rowindex, value, column){
                		var html = '';
                		if(value == '01'){
                			html = '待支付';
                		}else if(value == '02'){
                			html = '已支付';
                		}else if(value == '03'){
                			html = '已成功';
                		}else if(value == '04'){
                			html = '已完成';
                		}else if(value == '05'){
                			html = '已取消';
                		}else if(value == '06'){
                			html = '挂起';
                		}
						 
						return html; 
					}
                },
                { display: '订单总金额', name: 'totalFee',isSort : false, width: 100,
                	render: function (record, rowindex, value, column){
                		var html = '￥'+record.totalFee;
                		return html; 
                	},totalSummary:{
                		render:function(suminf,column,cell){
                			return'总计 '+suminf.sum+"元"+"<br>最大"+suminf.max+"元";
                		}
                	}
                },
                { display: '备注', name: 'memo',isSort : false, width: 200 }
                <sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_CUSTOM">,
                {
                	display: '操作', 
                	name: 'status',
                	isAllowHide: false, 
                	isSort : false,
					render: function (record, rowindex, value, column){
					//this     这里指向grid
					//record   行数据
					//rowindex 行索引
					//value    当前的值，对应record[column.name]
					//column   列信息
					//alert("${userId}");
					if("${userId}"==record.lock){
						//alert("${userId}");
						var html=' <a onclick="cancel(\''+ record.id + '\')" href="javascript:;">取消  </a> ';
							if(record.status=='02' && record.payFrom=="01"){
								html+= ' <a onclick="define(\''+ record.id + '\')" href="javascript:;">确定</a> ';
							}else if(record.payFrom=="02" && record.status!='03'){
								html+= ' <a onclick="define(\''+ record.id + '\')" href="javascript:;">确定</a> ';
							}
							if(record.type=='02'){
								html += '  <a onclick="sendHotelFax(\''+ record.id + '\')" href="javascript:;">发传真</a>'; 
							}
						
							return html; 
						}
					}
                }
                 </sec:authorize>
                ], 
                pageSize:10,
                root :'list',
                record:'totalRecord',
                url: "/misc/order/orderGrid.htm", 
                width: '99%',height:'99%',
                isChecked: f_isChecked
            });


	});
	
	function audiSuc(orderId){
		$.ligerDialog.confirm('你确定要审核通过该产品吗？', 
			function (yes){
				if(yes){
					$.post("/misc/order/audiSuc.htm",{orderId:orderId},
						function(data){
							grid_ae.loadData();
						}
					); 
					
				}
			});
	}
	
	function define(orderId){
		$.ligerDialog.confirm('你确定要通过该订单并发短信吗？状态会更改为“已成功”。', 
				function (yes){
					if(yes){
						$.post("/misc/order/defineOrder.htm",{orderId:orderId},
							function(data){
								grid_ae.loadData();
							}
						); 
						
					}
				});
	}
	
	function cancel(orderId){
		$.ligerDialog.confirm('你确定取消该订单并发短信吗？状态会更改为“已取消”。', 
				function (yes){
					if(yes){
						$.post("/misc/order/cancelOrder.htm",{orderId:orderId},
							function(data){
								grid_ae.loadData();
							}
						); 
						
					}
				});
	}
	function sendHotelFax(orderId){
		$.ligerDialog.confirm('你确定要给酒店发传真吗？', 
			function (yes){
				if(yes){
					$.post("/misc/order/sendHotelFax.htm",{orderId:orderId},
						function(data){
							grid_ae.loadData();
						}
					); 
					
				}
			});
	}
	
	function search(){
		grid_ae.options.parms = [{name:'startTime',value:$("#startTime").val()},{name:'endTime',value:$("#endTime").val()},{name:'contactor',value:$("#search_contactor").val()},{name:'company',value:$("#company").val()},{name:'status',value:$("#search_status").val()},{name:'id',value:$("#order_num").val()},{name:'type',value:$("#search_type").val()}];
		grid_ae.loadData();
	}
	//订单详情
	function detail(id){
		dialog_ae = $.ligerDialog.open({ height: 700,width:1200, url: "/misc/order/orderdtl.htm?id="+id, showMax:true,showMin:true,isResize:true,isDrag:false,title:'订单详情'});
	}
	/* //发送短信
	function sendMsg(id,phone){
		dialog_ae = $.ligerDialog.open({ height: 300,width:1200, url: "/misc/order/sendMsg.htm?id="+id+"&phone="+phone, showMax:true,showMin:true,isResize:true,isDrag:false,title:'发送短信'});
	} */
	//查看产品详情
	function  typeDetail(pid,type){
		if(type=="01"){
			window.open ("/ticket.htm?id="+pid);
		}else if(type=="02"){
			window.open ("/hotel.htm?rid="+pid);
		}else if(type=="03"){
			window.open ("/product.htm?id="+pid);
		}
		
	}
	function f_isChecked(data)
    {
		 //alert(data.lock);
		 if(IsNull(data.lock)){
			 return false;
		 } 
		 //alert(data.lock);
		 return true;
		
       // return false;
    }
	//
	/*
	function pushProduct(){
	var channel = $("#parent").ligerGetComboBoxManager().getValue();
	if(channel == ""){
		$.ligerDialog.warn("请选择所属栏目！");
		return;
	}else if(contentList.length==0){
		$.ligerDialog.warn("请选择推送内容！");
		return;
	}
	var contentArr = [];
	for(var i=0; i<contentList.length; i++){
		contentArr.push({
			"id" : contentList[i].id,
			"title" : contentList[i].name,
			"price" : contentList[i].priceMin,
			"content" : contentList[i].special,
			"picture" : contentList[i].image1,
			"picture2" : contentList[i].image2,
			"summary" : contentList[i].special,
			"hyperlink" : "product.htm?id="+contentList[i].id
		});
	}
	$("#tui_song").attr("onclick","");
	//提交数据
	$.post("/misc/cms/commendContent.htm",{
		contentList : $.toJSON(contentArr),
		channel : channel,
		tblName : "coolsk_product"
	},function(data){
		if(data=="error"){
			$.ligerDialog.warn("亲，系统现在有点抽经，这次操作没有成功！");
		}else if(data==0){
			$.ligerDialog.success("亲，"+contentList.length+"条内容推送成功！");
			removeCheckedata();
		}else if(contentList.length==data){
			$.ligerDialog.warn("亲，您推送的这"+contentList.length+"条内容该栏目已经有了，您还是换个吧！");
		}else{
			$.ligerDialog.success("亲，您推送的内容有"+data+"个该栏目已经有了，另外"+(contentList.length-data)+"条成功了！");
			removeCheckedata();
		}
		$("#tui_song").attr("onclick","pushProduct()");
		//loadDate();
	});
}
	*/
	
	
	
	
	
	
	
</script>
<table style="height: 40px;">
	<tr>
		<td>
			订单号：<input type="text" id="order_num" style="width: 120px;height: 22px;" value="${orderNum}" name="orderNum" />
		</td>
		<td>联系人：<input id="search_contactor" type="text" value="${name}" style="width: 120px;height: 22px;"/></td>
		<td>所属公司：</td>
		<td><%@include file="../company/companyName.jsp" %></td>
		<td>
			订单状态：<select name="company" id="search_status">
					<option value="">请选择</option>
					<option value="01">待支付</option>
					<option value="02">已支付</option>
					<option value="03">已成功</option>
					<option value="04">已完成</option>
					<option value="05">已取消</option>
				</select>
		</td>
		<td>
			订单分类：<select name="type" id="search_type">
							<option value="">请选择</option>
							<option value="01">门票</option>
							<option value="02">酒店</option>
							<option value="03">产品</option>
				    </select>
		</td>
		<td>
			开始时间：<input class="Wdate"  type="text" id="startTime" style="width: 120px;"  readonly="readonly" name="startTime" onclick="WdatePicker({el:'startTime',dateFmt:'yyyy-MM-dd',readOnly:true,isShowClear:false});"/>
		</td>
		<td>
			结束时间：<input class="Wdate"  type="text" id="endTime" style="width: 120px;"  readonly="readonly" name="endTime" onclick="WdatePicker({el:'endTime',dateFmt:'yyyy-MM-dd',readOnly:true,isShowClear:false});"/>
		</td>
		
		<td><input id="btnOK" type="button" value="查询" onclick="search()" /></td>
		
	</tr>
</table>
<%-- <div id="searchbar">
   联系人：<input id="search_contactor" type="text" value="${name}"/>   所属公司：<select name="company" id="search_company">
					<option value="">请选择</option>
					<c:forEach items="${companyModel.list}" var="comp">
						<option value="${comp.id}"
						<c:if test="${product.company==comp.id }">SELECTED</c:if>
						>${comp.name}</option>
					</c:forEach>
				</select>	
				  订单状态：<select name="company" id="search_status">
					<option value="">请选择</option>
					<option value="01">待支付</option>
					<option value="02">已支付</option>
					<option value="03">已成功</option>
					<option value="04">已完成</option>
					<option value="05">已取消</option>
				</select>	
    <input id="btnOK" type="button" value="查询" onclick="search()" />
</div> --%>
<div id="order_grid" style="margin:0; padding:0"></div>
